package com.yueguanjia.pay;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;

import com.jielin.customer.R;

import cmb.pb.util.CMBKeyboardFunc;

/**
 * Created by Milo on 16/7/10.
 * 银行支付
 */
public class BankPayActivity extends Activity {

    private WebView webView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        // 自定义标题栏
        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.bank_pay_layout);
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.bank_pay_title);

        webView = (WebView) findViewById(R.id.bank_pay_web_view);

        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setSaveFormData(false);

        webView.loadUrl("http://61.144.248.29:801/netpayment/BaseHttp.dll?PrePayEUserP?BranchID=0021&CoNo=000093&BillNo=1510530408&Amount=180.00&Date=20160715&ExpireTimeSpan=30&MerchantUrl=http://121.43.235.99/jielin-web/cmb/notify/order&MerchantPara=DD1607151053005677%7C19766%7C40967&MerchantCode=%7CVULiSYKuOBI0qD04i/G0aiugKIsnyMPVeuGQyd1HYgejdB4XkURvRSIDWyfQ2OOwxhNbKkglpUy3kShM7oNuMJrsyyeLPvObMEmwR3LqA6f0lyTkuUwIh2XXyLQHiqhz1sl72R7ycubW1PRxdY27oD39/6beLfjqk6Gy9TBdFbmyAfpR*F7Kq9dN*MTZvN1Sd*eJpq1CnxNc/VERA/D4proVPZRvW/ivbUSY*oFS1zJpZmCALk/D6X4XMlQ8xOs5ddLAhl00NR8lqoYBm0YVjqVOBfX80lFszMh9nqn7iAq9dqzZV7wXbTATWFCiYgsshmz1duabnmQH5Ed0QzCpoDPl75B6pQxf05jDYABjrIqL4ponzzgWUCn/8snXm6zzbB9CzFBQIzYmkIOxDP8oiX3ffv*utsghYLAaz3jVSljLg8WAZG/Bk41fCaTKg9MVDtsNokLUNaBm6HcWXFwKRV8pJUY/GL7TCdP9DcPZ3x/Io32QDERpj3E5Yr7fxm37dm0sbMORDfiP0TSIJd9FZIzMpnI=%7Cb96e7cec662cca965f010b265efb23c137768fc9&MerchantRetUrl=http://test.yueguanjia.com/jielin-web/%23/tab/wechat/orders&MerchantRetPara=");

        // 自定义WebViewClient
        webView.setWebViewClient(new WebViewClient() {

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {

                Log.d("TEST", "url = " + url);

                // 创建招商银行安全键盘
                CMBKeyboardFunc kbFunc = new CMBKeyboardFunc(BankPayActivity.this);

                // 判断URL是否为安全键盘访问地址
                if (kbFunc.HandleUrlCall(view, url) == false) {
                    return super.shouldOverrideUrlLoading(view, url);
                } else {
                    return true;
                }

            }

        });

        // 未完成支付返回
        ImageView backBtn = (ImageView) findViewById(R.id.header_left_btn);

        backBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {

                AlertDialog dialog = new AlertDialog.Builder(BankPayActivity.this)
                        .setTitle("提示")
                        .setMessage("支付还没有完成,您确定返回吗?")
                        .setPositiveButton("确定", new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {

                                dialog.dismiss();
                                BankPayActivity.this.finish();

                            }

                        })
                        .setNegativeButton("取消", new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                            }

                        }).show();

            }
        });

    }
}